<template>
  <view>
    <web-view :src="src" v-if="src" @load="onWebLoad"></web-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      src: "",
      title: "",
    };
  },

  onShareAppMessage() {
    const query = uni.$h.queryParams({
      title: this.title,
      src: this.src,
    });
    return {
      title: this.title,
      path: "/pages/webview/webview" + query,
    };
  },
  onLoad({ src, title }) {
    this.src = decodeURIComponent(src);
    if (title) {
      this.title = decodeURIComponent(title);
    }
  },
  onShow() {
    this.setTitle();
  },
  methods: {
    setTitle() {
      if (this.title) {
        uni.$h.setTitle(this.title);
      }
    },
    onWebLoad() {
      this.setTitle();
      setTimeout(() => {
        this.setTitle();
      }, 500);
    },
  },
};
</script>
